package com.dunshan.prcexp.pojo;

import com.dunshan.prcexp.config.IAction.Http;
import com.dunshan.prcexp.config.IConfig;
import com.dunshan.prcexp.config.IConfig.HttpCallType;
import com.dunshan.prcexp.config.IConfig.Env;

import java.util.Map;

/**
 * @author liwen406
 * @program: dunshan-pef
 * @description:
 * @date 2022-08-24 17:20:13
 */
public class HttpEntity {
    private final IConfig.Env env;
    private final IConfig.HttpCallType callType;
    private final String url;
    private final String ip;
    private final Http method;
    private String info;
    private final Map<String, String> queryParams;
    private final Map<String, ?> parameter;
    private final Map<String, String> headers;
    private final Map<String, String> formBodies;
    private final String body;
    private final Boolean signature;

    public HttpEntity(HttpEntity.Builder builder) {
        this.env = builder.getEnv();
        this.callType = builder.getCallType();
        this.url = builder.getUrl();
        this.ip = builder.getIp();
        this.method = builder.getMethod();
        this.queryParams = builder.getQueryParams();
        this.parameter = builder.parameter;
        this.headers = builder.getHeaders();
        this.formBodies = builder.getFormBodies();
        this.body = builder.getBody();
        this.signature = builder.getSignature();
        this.info = builder.info;
    }

    public HttpEntity.Builder newBuilder() {
        return new HttpEntity.Builder(this);
    }

    public Env getEnv() {
        return this.env;
    }

    public HttpCallType getCallType() {
        return this.callType;
    }

    public String getUrl() {
        return this.url;
    }

    public String getIp() {
        return this.ip;
    }

    public Http getMethod() {
        return this.method;
    }

    public Map<String, String> getQueryParams() {
        return this.queryParams;
    }

    public Map<String, String> getHeaders() {
        return this.headers;
    }

    public Map<String, String> getFormBodies() {
        return this.formBodies;
    }

    public String getBody() {
        return this.body;
    }

    public String getInfo() {
        return this.info;
    }

    public Boolean getSignature() {
        return this.signature;
    }

    public Map<Object, Object> getParameter() {
        return null;
    }

    public boolean isOnGate() {
        return false;
    }

    public static class Builder {
        private Env env;
        private HttpCallType callType;
        private String url;
        private String ip;
        private Http method;
        String info;
        private Map<String, String> queryParams;
        Map<String, ?> parameter;
        private Map<String, String> headers;
        private Map<String, String> formBodies;
        private String body;
        private Boolean signature;

        public Builder() {
            this.env = Env.LOCAL;
            this.callType = HttpCallType.HOST;
            this.url = "";
            this.ip = "";
            this.info = "";

            this.method = Http.GET;
            this.queryParams = null;
            this.headers = null;
            this.formBodies = null;
            this.body = "";
            this.signature = false;
        }

        public Builder(HttpEntity httpEntity) {
            this.env = httpEntity.getEnv();
            this.callType = httpEntity.getCallType();
            this.url = httpEntity.getUrl();
            this.ip = httpEntity.getIp();
            this.method = httpEntity.getMethod();
            this.info = httpEntity.info;
            this.parameter = httpEntity.parameter;
            this.queryParams = httpEntity.getQueryParams();
            this.headers = httpEntity.getHeaders();
            this.formBodies = httpEntity.getFormBodies();
            this.body = httpEntity.getBody();
            this.signature = httpEntity.getSignature();
        }

        public HttpEntity.Builder env(Env env) {
            this.env = env;
            return this;
        }

        public HttpEntity.Builder callType(HttpCallType callType) {
            this.callType = callType;
            return this;
        }

        public HttpEntity.Builder url(String url) {
            this.url = url;
            return this;
        }

        public HttpEntity.Builder ip(String ip) {
            this.ip = ip;
            return this;
        }

        public HttpEntity.Builder info(String info) {
            this.info = info.trim();
            return this;
        }

        public HttpEntity.Builder method(Http method) {
            this.method = method;
            return this;
        }

        public HttpEntity.Builder queryParams(Map<String, String> queryParams) {
            this.queryParams = queryParams;
            return this;
        }

        public HttpEntity.Builder headers(Map<String, String> headers) {
            this.headers = headers;
            return this;
        }

        public HttpEntity.Builder formBodies(Map<String, String> formBodies) {
            this.formBodies = formBodies;
            return this;
        }

        public HttpEntity.Builder body(String body) {
            this.body = body;
            return this;
        }

        public HttpEntity.Builder signature(Boolean signature) {
            this.signature = signature;
            return this;
        }

        public HttpEntity build() {
            return new HttpEntity(this);
        }

        public Env getEnv() {
            return this.env;
        }

        public HttpCallType getCallType() {
            return this.callType;
        }

        public String getUrl() {
            return this.url;
        }

        public String getIp() {
            return this.ip;
        }

        public Http getMethod() {
            return this.method;
        }

        public Map<String, String> getQueryParams() {
            return this.queryParams;
        }

        public Map<String, String> getHeaders() {
            return this.headers;
        }

        public Map<String, String> getFormBodies() {
            return this.formBodies;
        }

        public String getBody() {
            return this.body;
        }

        public Boolean getSignature() {
            return this.signature;
        }
    }
}
